var createError = require('http-errors');
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors');
//时间格式化



var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var apisRouter = require('./routes/apis');


var app = express();

//改写
var http = require('http');
var server = http.createServer(app);
app.use(express.urlencoded({
	extended: false
}));
app.use(cookieParser());
//静态资源
app.use(express.static(path.join(__dirname, 'public')));
//post请求
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
	extended: true
}));

//配置cors
// app.use(cors({
// 	origin: ['http://localhost:8080'],
// 	methods: ['GET', 'POST'],
// 	alloweHeaders: ['Conten-Type', 'Authorization']
// }))
app.use(cors())
//路由
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/api', apisRouter);
//开启端口
server.listen('3012');
// module.exports = app;
